/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.supinfo.youfood.web.servlet.admin.commande;

import com.supinfo.youfood.entity.Commande;
import com.supinfo.youfood.service.CommandeService;
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author TaKeO
 */
@WebServlet(name = "DetailCommandeServlet", urlPatterns = {"/admin/detail-commande"})
public class DetailCommandeServlet extends HttpServlet {
     
    @EJB
    private CommandeService commandeService;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        Commande commande = commandeService.findCommandeById(new Long(request.getParameter("id")));
        request.setAttribute("commande", commande);       
        
        double prix = 0;
        for(int i=0;i<commande.getList_menus().size();i++)
        {
            prix += commande.getList_menus().get(i).getMenu().getPrix();
        }
        
        for(int i=0;i<commande.getList_produits().size();i++)
        {
            prix += Math.round((commande.getList_produits().get(i).getProduit().getPrixHT()+commande.getList_produits().get(i).getProduit().getPrixHT()*commande.getList_produits().get(i).getProduit().getCategorie().getTVA()/100)*100)/100.0;
        }
        request.setAttribute("prix", prix);
        
        request.getRequestDispatcher("/jsp/admin/detail-commande.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        int i = 1;
    }
}
